package com.example.ucs_alg_node_manager.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.ucs_alg_node_manager.domain.Alg;
import com.example.ucs_alg_node_manager.service.AlgService;
import com.example.ucs_alg_node_manager.utils.RestTemplateUtil;
import com.example.ucs_alg_node_manager.utils.UcsPatterns;
import com.example.ucs_alg_node_manager.vo.ReturnVO;
import com.example.ucs_alg_node_manager.vo.SystemStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/alg")
@CrossOrigin
@Api("算法管理功能")
public class AlgController {

    @Resource
    private AlgService algService;

    @ApiOperation("获取算法信息")
    @GetMapping("/query")
    public ReturnVO query(@RequestParam("nodeId")Integer nodeId){
        return ReturnVO.ok(algService.getOne(Wrappers.<Alg>lambdaQuery().eq(Alg::getNodeId, nodeId))).message("查询成功");
    }

    @ApiOperation("修改算法信息")
    @PostMapping("/update")
    public ReturnVO update(@RequestBody Alg alg){
        return algService.updateAlg(alg);
    }

    @ApiOperation("修改算法模型")
    @PostMapping("/upload")
    public ReturnVO upload(@RequestParam("file")MultipartFile file,
                           @RequestParam("id")Integer algId){
        return algService.uploadModel(file, algId);
    }

    @ApiOperation("选择算法模型")
    @PostMapping("/select")
    public ReturnVO select(@RequestParam("model")String model, @RequestParam("id") Integer algId){
        return algService.selectModel(model, algId);
    }

    @ApiOperation("获取已经上传的算法模型")
    @GetMapping("/getModels")
    public ReturnVO getModels(){
        return algService.getModelList();
    }


}  
